<?php
/*
    Authors and license
*/

include_once(dirname(__FILE__).'/../config/config.php');
include_once(dirname(__FILE__).'/../libraries/lang/'.$lang.'.php');

 
if (isset($_GET['code'])) {

    $table = 'Users';
 
    $code = htmlspecialchars(stripslashes(strip_tags(trim($_GET['code']))), ENT_QUOTES); //$_GET['code'] filter
 
    // check if user is already activated, if not - set Confirmed=1
    $result = mysql_query("SELECT * FROM Users WHERE `Verification_code`='$code' and `Confirmed`=1");
    if (mysql_num_rows($result) == 1) {
        echo '<p>'.$lang_account_already_activated.'</p>';
        exit;
    } else {
        $result = mysql_query("UPDATE Users
         SET `Confirmed`=1 WHERE `Verification_code`='$code' and `Confirmed`=0") or die("Error: ". mysql_error(). " with query ". $query);
        $result = mysql_query("SELECT * FROM Users
         WHERE `Verification_code`='$code' and `Confirmed`=1") or die("Error: ". mysql_error(). " with query ". $query);
        if (mysql_num_rows($result) == 1) {
            echo $lang_mail_succ_activated;
			echo '<meta http-equiv="Refresh" content="3;url=index.php" />'; 
        }
    }
 
    // Wrong link
    if (!$code or mysql_num_rows($result)<>1) {
        echo '<p>'.$lang_mail_fail_activation.'</p>';
    } 
}
else echo '<meta http-equiv="Refresh" content="0;url=index.php" />'; 
 
?>